﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;

namespace l1cs.server.serverpackets
{
    public class S_FixWeaponList : ServerBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( S_FixWeaponList ).FullName );

        public S_FixWeaponList( L1PcInstance pc )
        {
            buildPacket( pc );
        }

        private void buildPacket( L1PcInstance pc )
        {
            writeC( Opcodes.S_OPCODE_SELECTLIST );
            writeD( 0x000000c8 ); // Price

            List<L1ItemInstance> weaponList = new List<L1ItemInstance>();
            object[] itemList = pc.getInventory().getItems();
            foreach ( L1ItemInstance item in itemList )
            {
                // Find Weapon
                switch ( item.getItem().getType2() )
                {
                    case 1:
                        if ( item.get_durability() > 0 )
                        {
                            weaponList.Add( item );
                        }
                        break;
                }
            }

            writeH( weaponList.Count ); // Weapon Amount

            foreach ( L1ItemInstance weapon in weaponList )
            {
                writeD( weapon.getId() ); // Item ID
                writeC( weapon.get_durability() ); // Fix Level
            }
        }

        override
        public byte[] getContent()
        {
            return getBytes();
        }

        override
        public String getType()
        {
            return "[S] S_FixWeaponList";
        }
    }
}